<?php
/*
	* 类与对象 属性
	* https://www.php.net/manual/zh/language.oop5.properties.php
	* Adair  zouhdai@gmail.com
	* 2021-08-17
*/


$ref = new StdClass();
$ref->{'ref-type'} = 'Journal Article';
var_dump($ref);


echo "\n<BR \>"." --- Public属性没有变化.  Protected 属性为 '*'.  Private属性为 ；类名+属性名 --- "."\n<BR \>";

 
class test
{
    public $var1 = 1;
    protected $var2 = 2;
    private $var3 = 3;
    static $var4 = 4;
   
    public function toArray()
    {
        return (array) $this;
        //return array($this);
    }

    public function objectThis($array = null) {
    	//var_dump($array,!$array);
	    if (!$array) {
	    	//echo 111;
	        foreach ($this as $property_name => $property_values) {
	            if (is_array($property_values) && !empty($property_values)) {
	            	echo 'a';
	                $this->{$property_name} = $this->objectThis($property_values);
	            } else if (is_array($property_values) && empty($property_values)) {
	            	echo 'b';
	                $this->{$property_name} = new stdClass();
	            }
	        }
	    } else {
	    	
	        $object = new stdClass();
	        foreach ($array as $index => $values) {
	            if (is_array($values) && empty($values)) {
	            	echo 1;
	                $object->{$index} = new stdClass();
	            } else if (is_array($values)) {
	            	echo 2;
	                $object->{$index} = $this->objectThis($values);
	            } else {
	            	echo 3;
	                $object->{$index} = $values;
	            }
	        }
	        return $object;
	    }
	}
}

$t = new test;
print_r($t->toArray());

$rst1 = $t->objectThis($array ="");


$arr2_1 = array(array());
$arr2_2 = array('a'=>'1','b'=>array('c'=>'2'));
$arr2_3 = array('a'=>'1','b'=>'2');


$rst2_1 = $t->objectThis($arr2_1);
$rst2_2 = $t->objectThis($arr2_2);
$rst2_3 = $t->objectThis($arr2_3);
var_dump($rst1,$rst2_1,$rst2_2,$rst2_3);